package translated;

import java.util.*;
import edu.pku.sei.modeler.model.core.*;
import edu.pku.sei.modeler.jet.util.*;

public class PackageGen
{
  protected static String nl;
  public static synchronized PackageGen create(String lineSeparator)
  {
    nl = lineSeparator;
    PackageGen result = new PackageGen();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "/**" + NL + " * Copyright (c) Software Institude of PKU" + NL + " * All rights reserved. " + NL + " * This program and the accompanying materials" + NL + " * are made available under the terms of the Eclipse Public License v1.0" + NL + " * which accompanies this distribution, and is available at" + NL + " * http://www.eclipse.org/legal/epl-v10.html" + NL + " *" + NL + "*/" + NL + "package ";
  protected final String TEXT_2 = ";" + NL + "// imports:" + NL + "import edu.pku.sei.modeler.model.common.*;" + NL + " " + NL + "/**" + NL + " * @generated" + NL + " *" + NL + " */" + NL + "public class ModelPackage extends AbstractPackage {" + NL + "\t// string for namespace" + NL + "\tpublic static final String packageName = \"model\";" + NL + "\tpublic static final String NS_PREFIX = \"generated.model\";" + NL + "\tpublic static final String __METAPACKAGE__ = \"MetaPackage\";" + NL + "\tpublic static final String __METAMODEL__ = \"GeneratedModel\";" + NL + "\t// string for elements & attributes" + NL + "\t";
  protected final String TEXT_3 = NL + "\tpublic static final String __";
  protected final String TEXT_4 = "__ = \"";
  protected final String TEXT_5 = "\";" + NL + "\t";
  protected final String TEXT_6 = NL + "\tpublic static final String ";
  protected final String TEXT_7 = "_";
  protected final String TEXT_8 = " = \"";
  protected final String TEXT_9 = "\";" + NL + "\t";
  protected final String TEXT_10 = NL + "\tpublic static final String ";
  protected final String TEXT_11 = "_";
  protected final String TEXT_12 = " = \"";
  protected final String TEXT_13 = "\";" + NL + "\t";
  protected final String TEXT_14 = NL + "}" + NL + NL + NL + NL + NL + NL + NL + NL + NL + NL;
  protected final String TEXT_15 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
     List modelList = (List) argument; 
    stringBuffer.append(TEXT_1);
    stringBuffer.append(ModelerConstants.pkgBase + "." + ModelerConstants.modelBase);
    stringBuffer.append(TEXT_2);
    
		for(int i=0; i<modelList.size(); i++) {
			MetaClass cls = (MetaClass)modelList.get(i);
			String name = cls.getName();
//			name = name.replace(".","_");
	
    stringBuffer.append(TEXT_3);
    stringBuffer.append(name.toUpperCase());
    stringBuffer.append(TEXT_4);
    stringBuffer.append(name);
    stringBuffer.append(TEXT_5);
    
			List attrs = new ArrayList();
			attrs.addAll(cls.getAttributes());
			attrs.addAll(cls.getDerivedAttributes());
			for(int j=0; j<attrs.size(); j++) {
				MetaAttribute attr = (MetaAttribute)attrs.get(j);
				String attrName = attr.getName();
	
    stringBuffer.append(TEXT_6);
    stringBuffer.append(cls.getName().toUpperCase());
    stringBuffer.append(TEXT_7);
    stringBuffer.append(attrName.toUpperCase());
    stringBuffer.append(TEXT_8);
    stringBuffer.append(attrName);
    stringBuffer.append(TEXT_9);
    		}
			List refs = cls.getReferences();
			for(int j=0; j<refs.size(); j++) {
				MetaReference ref = (MetaReference)refs.get(j);
				String refName = ref.getName();
	
    stringBuffer.append(TEXT_10);
    stringBuffer.append(cls.getName().toUpperCase());
    stringBuffer.append(TEXT_11);
    stringBuffer.append(refName.toUpperCase());
    stringBuffer.append(TEXT_12);
    stringBuffer.append(refName);
    stringBuffer.append(TEXT_13);
    		}
		}
	
    stringBuffer.append(TEXT_14);
    stringBuffer.append(TEXT_15);
    return stringBuffer.toString();
  }
}
